package com.s3.khospitalds.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.s3.khospitalds.common.ResponseEntity;
import com.s3.khospitalds.entity.Doctor;
import com.s3.khospitalds.entity.Shiftlist;
import com.s3.khospitalds.entity.TableShift;
import com.s3.khospitalds.mapper.ShiftlistMapper;
import com.s3.khospitalds.service.ShiftlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 想要告诉你
 * @CreateTime: 2025/3/7 15:00
 * @Description: 医生轮班类
 * @Version: 1.0
 */
@Service
public class ShiftlistServiceImpl extends ServiceImpl<ShiftlistMapper, Shiftlist> implements ShiftlistService {
    @Autowired
    private ShiftlistServiceImpl shiftlistService;
    @Autowired
    private ShiftlistMapper shiftlistMapper;

    @Override
    public ResponseEntity selectShiftlist(int pageNum, int pageSize, String searchDepartment, String searchName, String searchTimes) {
        ResponseEntity responseEntity = new ResponseEntity();
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        //模糊查询
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (searchDepartment!=""){
            queryWrapper.eq("office",searchDepartment);
        }
        if (searchTimes!="") {
            queryWrapper.eq("dates", searchTimes);
        }
        queryWrapper.like("name",searchName);
        //使用分页查询
        List<Doctor> shiftlist = shiftlistService.list(queryWrapper);
        //创建分页的对象
        PageInfo<Doctor> pageInfo = new PageInfo<>(shiftlist);
        //设置响应对象的值
        responseEntity.setCount((int) pageInfo.getTotal());
        //设置响应对象的行数据
        responseEntity.setData(pageInfo.getList());
        return responseEntity;
    }

    @Override
    public int insertShiftlist(Shiftlist shiftlist) {
        return shiftlistMapper.insert(shiftlist);
    }

    @Override
    public int updateShiftlist(Shiftlist shiftlist) {
        return shiftlistMapper.updateById(shiftlist);
    }

    @Override
    public int deleteShiftlist(int id) {
        return shiftlistMapper.deleteById(id);
    }
}
